import requests

class Config:
    def __init__(self, base_url='http://10.59.9.12:7001'):
        self.url = base_url
        self.session = requests.Session()
        # 设置默认请求头
        self.session.headers.update({
            'Content-Type': 'application/json',
        })
    def request(self, method, path,** kwargs):
        """通用请求方法，通过 **kwargs 接收所有请求参数"""
        url = f"{self.url}{path}"
        print(f"\n发送{method}请求: {url}")
        # 支持所有 requests 支持的参数（如 timeout、cookies、headers 等）
        try:
            response = self.session.request(method, url, **kwargs)
            print(f"响应状态码: {response.status_code}")
            return response
        except requests.exceptions.RequestException as e:
            print(e)
    def get(self, path,** kwargs):
        """GET请求：支持所有扩展参数"""
        return self.request("GET", path, **kwargs)
    def post(self, path,** kwargs):
        """POST请求：支持json/data/headers等参数"""
        return self.request("POST", path, **kwargs)
    def put(self, path,** kwargs):
        """PUT请求：支持扩展参数"""
        return self.request("PUT", path, **kwargs)
    def delete(self, path,** kwargs):
        """DELETE请求：支持扩展参数"""
        return self.request("DELETE", path, **kwargs)